package com.yylending.las.lending.quota.face;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;
import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by laixj on 2016/11/18.
 * Copyright © 2016 www.yyfax.com. All Rights Reserved.
 */
public class FaceModel extends Model {

	private static final String TAG = "FaceModel";

	public final static int METHOD_SAVE = 0;

	@Override
	public Observable getObservable(Object params, int functionalCode) {

		switch (functionalCode) {
			case METHOD_SAVE:{
				Service service = (Service) NetworkHelper.createService(Service.class, 30);
				return service.saveFaceInfo(Global.LOGIN_TOKEN, (AESEntity) params);}
		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		CLog.i(TAG, "onNext: " + entity.toString());
		BaseResultEntity result = cast(entity);
		switch (result.requestCode) {
			case METHOD_SAVE:
				SaveFaceResult saveFaceResult = cast(entity);
				EventAgent.post(saveFaceResult);
				break;
		}
	}

	private interface Service {
		/**
		 * 人脸信息录入接口
		 */
		@POST("server/customer/verifyPhoto")
		Observable<SaveFaceResult> saveFaceInfo(@Header("token") String token, @Body AESEntity params);
	}

	static class SaveFaceResult extends BaseResultEntity<EmptyEntity> {
	}

	public static class FaceStatus {
		public String status;
		public String isPassed;
	}

	public static class SaveFace {
		public String sface;

		public SaveFace(String sface) {
			this.sface = sface;
		}
	}
}